
clear 
set scheme lean2, permanent
global pm = char(177) 
set more off

gl date = c(current_date)
if c(os) == "MacOSX" gl user "/Users/`c(username)'"
else if c(os) == "Windows" gl user "C:\Users\\`c(username)'"
else if c(os) == "Unix" gl user "/usr/`c(username)'"
di "$user

set graphics on  
 
global path_data_processed "\data\processed"
global path_output "\data\output"

 
clear all
set more off

cd "$path_data_processed"
use "robustnessexperiment3.dta", clear

cd "$path_output"
 
drop if t15med==1

global controls female atleast_bachelor age agesq log_inc midwest south west inc_NR

loc experiments "unemp_prob z_profits"




		  
preserve

clear all
eststo clear
estimates drop _all

set obs 10
qui gen x = 1
qui gen y = 1

loc columns = 0

foreach choice in `experiments' {

    loc ++columns
    qui eststo col`columns': reg x y

}

restore


/* Statistics */

loc colnum = 1
loc colnames ""







foreach choice in `experiments' {


***OLS


    qui reg `choice' posterior $controls, r, if t15avg==1|t30==1|t5==1
    sigstar posterior, prec(3)
    estadd loc thisstat4 = "`r(bstar)'": col`colnum'
    estadd loc thisstat5 = "`r(sestar)'": col`colnum'
	qui sum `choice' if t15avg==1|t30==1|t5==1
    *estadd loc thisstat7 = r(N): col`colnum'

	
***IV
	
    qui ivreg2 `choice' (posterior = signal) $controls, r first, if t15avg==1|t30==1|t5==1
	mat firststage = e(first)
	mat r2=e(r2)
	sigstar posterior, prec(3)
    estadd loc thisstat10 = "`r(bstar)'": col`colnum'
    estadd loc thisstat11 = "`r(sestar)'": col`colnum'
	qui sum `choice'  if t15avg==1|t30==1|t5==1
    estadd loc thisstat13 = r(N): col`colnum'	
	*estadd loc thisstat14 = string(r2[1,1], "%9.2f"): col`colnum'	
	estadd loc thisstat15 = string(r(mean), "%9.2f"): col`colnum'
	estadd loc thisstat16 = string(r(sd), "%9.2f"): col`colnum'	
	estadd loc thisstat17 = string(firststage[8,1], "%9.2f"): col`colnum'	
			
	loc ++colnum
    loc colnames "`colnames' `"`: var la `choice''"'"

}
	
loc rowlabels " " " "{\bf Panel A: OLS}" " " "Posterior: Recession" " " " " "\hline" "{\bf Panel B: IV}" " " "Posterior: Recession" "  " " " "Observations" " " "Mean dep. var." "SD dep. var." "First stage F-stat" " "   "\hline" " "   "
loc rowstats ""

forval i = 1/17 {
    loc rowstats "`rowstats' thisstat`i'"
}

esttab * using "table_macro_RRpilot.tex", replace cells(none) booktabs nonotes nomtitles compress alignment(c) nogap noobs nobaselevels label stats(`rowstats', labels(`rowlabels')) ///
   mgroups("\shortstack{National\\unemployment\\(percent)}" "\shortstack{Firm\\profits\\(categorical)}" ///
  , pattern(1 1 ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))

	
	

	
	
eststo clear	



